package org.offsync.rich

import java.nio.channels.SocketChannel
import org.offsync.old.async.AsyncReturn
import org.offsync.old.async.AsyncService
import java.nio.channels.SelectionKey

class RichSocketChannel(val channel: SocketChannel) {
  def onReadReady(
      selector: AsyncService)(
          f: () => Unit) = {
    selector.invoke { () =>
      selector.register(channel, SelectionKey.OP_READ)(f) // TODO: Fix me
    }
  }

  def onWriteReady(
      selector: AsyncService)(
          f: () => Unit): AsyncReturn = {
    selector.invoke { () =>
      selector.register(channel, SelectionKey.OP_WRITE)(f)
    }
  }
}
